from wordcloud import WordCloud
import jieba
import numpy
import PIL.Image as Image
# 1.分词
def chinese_jieba(text):
    wordlist_jieba = jieba.cut(text)
    space_wordlist = " ".join(wordlist_jieba) # 空格连接字符
    return space_wordlist
# 2.读取文本
with open("test.txt", encoding="utf-8")as file:
    text = file.read()
    text = chinese_jieba(text)
    # print(text)
# 3.图片遮罩层
mask=numpy.array(Image.open("1.jpeg"))
print(mask)
# 4.将参数mask设值为：mask_pic
wordcloud = WordCloud(font_path="./WawaSC-Regular.otf", mask=mask,background_color='white').generate(text)
image = wordcloud.to_image()
image.save('./2.png')
# image.show()